<template>
	<view class="index">
		<view class="search-wrapper">
			<input confirm-type="search" @confirm="downCallback" type="text" v-model="keywords" class="input"
				placeholder="输入供应商名称查询" />
			<uni-icons v-if="keywords" type="clear" @tap="keywords = ''" size="18" color="#898989"
				class="close"></uni-icons>
			<image src="../static/image/search-icon.png" class="icon" mode="widthFix"></image>
			<view class="search-btn" @click="downCallback">
				搜索
			</view>
			<view class="search-btn scan" @click="scan">
				手机扫码
			</view>
		</view>
		<view class="search-wrapper">
			<view class="date-wrapper">
				<view class="label">
					回单日期：
				</view>
				<uni-datetime-picker @change="downCallback" type="date" v-model="single">
					<text>{{ dateStr }}</text>
					<uni-icons type="bottom" size="14" class="icons" color="#666666"></uni-icons>
				</uni-datetime-picker>
			</view>
			<view class="date-wrapper" v-if="supplyDate">
				<view class="label">
					供货日期：
				</view>
				<text>{{ supplyDate }}</text>
			</view>
		</view>
		<mescroll-uni ref="mescrollRef" height="100%" @init="mescrollInit" bottom="150" :down="downOption"
			@down="downCallback" :up="upOption" @up="upCallback">
			<!-- 数据列表 -->
			<view class="item" v-for="(item,index) in list" :key="index" @click="goDetail(item)">
				<view class="supplier-wrapper">
					<view class="supplier-info">
						<view class="name">{{ item.supplierName }}</view>
						<uni-icons v-if="item.supplierTel" type="phone" size="18" class="icon"
							color="#434343"></uni-icons>
						<text class="tel" @click.stop="callPhone(item.supplierTel)">{{ item.supplierTel }}</text>
					</view>
					<view class="supplier-address">
						{{ item.businessAddress }}
					</view>
				</view>
				<view class="product-info">
					<view class="info-wrapper" style="justify-content: space-between;">
						<text>交货单：{{ item.code }}</text>
						<uni-icons type="right" color="#999999" size="16"></uni-icons>
					</view>
					<view class="info-wrapper">
						城市仓：{{ item.cityCode }}{{item.cityName}}.{{item.pickupPointCode}}{{item.pickupPointName}}
					</view>
					<view class="info-wrapper" v-for="(items,indexs) in item.vehicleList" :key="indexs">
						<view class="label">
							{{ indexs === 0 ? '停车位：': '' }}
						</view>
						<text style="margin-right: 40upx;">{{ items.parkingSpace }}</text>
						<text>{{ items.vehicleCode }}</text>
					</view>
				</view>
				<view class="testing-wrapper">
					<view class="testing-title">
						<text class="date">回单时间：{{ item.confirmTime }}</text>
					</view>
					<view class="testing-title">
						<text class="date">交货件数：{{ item.confirmQuantity }}件</text>
						<text class="date">缺货件数：{{ item.pendingQuantity }}件</text>
					</view>
					<!-- 				<view class="images-wrapper" v-if="item.rejectImage">
						<image @click.stop="openPic(indexs,item.rejectImage.split(','))" :key="indexs"
							v-for="(url,indexs) in item.rejectImage.split(',')" :src="url" mode="aspectFill"
							class="reject-image"></image>
					</view> -->
				</view>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import {
		scanCode
	} from '@/uni_modules/lime-scan';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js";
	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		data() {
			return {
				downOption: {
					auto: true // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					auto: false, // 不自动加载
					textNoMore: '没有更多啦~',
					noMoreSize: 3, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						fixed: true,
						top: '200upx',
						tip: '~ 空空如也 ~', // 提示
						icon: 'https://sm.hobon.cc/static/hobon_noorder.png',
						zIndex: 1
					}
				},
				isLoading: true,
				list: [],
				pageNum: 1,
				pageSize: 10,
				keywords: '',
				supplyDate: '',
				single: this.$helper.getDay(0, '-')
			}
		},
		onLoad(option) {
			if (option.keywrods) {
				this.keywords = option.keywrods;
				this.supplyDate = option.supplyDate;
			}
		},
		computed: {
			dateStr() {
				let str = '';
				if (this.single === this.$helper.getDay(0, '-')) {
					str += '今天 ';
				} else if (this.single === this.$helper.getDay(-1, '-')) {
					str += '昨天 ';
				} else if (this.single === this.$helper.getDay(-2, '-')) {
					str += '前天 ';
				} else if (this.single === this.$helper.getDay(1, '-')) {
					str += '明天 ';
				}
				str += this.single.substring(5);
				return str;
			},
		},
		methods: {
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			async upCallback(page) {
				//let status = ['1', '2', '10', '11', '3']
				this.pageNum = page.num;
				const params = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					supplierKeyword: this.keywords,
					supplyDate: this.supplyDate,
					confirmTimeStart: this.single + ' 00:00:00',
					confirmTimeEnd: this.single + ' 23:59:59',
					orders: [{
						"asc": false,
						"column": "id"
					}],
				};
				const data = await this.$api.post('/adm/supply/record/page', params, false)
				if (data.code === 200) {
					this.isLoading = false;
					if (this.pageNum === 1) {
						this.list = [];
					}
					this.list = this.list.concat(data.data.records);
					this.mescroll.endBySize(data.data.records.length, data.data.total);
				} else {
					this.mescroll.endErr();
				}
			},
			callPhone(tel) {
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
			openPic(index, urls) {
				uni.previewImage({
					urls: urls,
					current: index
				});
			},
			scan() {
				scanCode({
					success: async (res) => {
						console.log(res)
						if (res.result.indexOf('code') > -1) {
							const code = JSON.parse(res.result).code;
							uni.navigateTo({
								url: '/subPage_receiptOrder/receipt?code=' + code
							})
						} else {
							uni.showToast({
								title: '无效的回单码',
								icon: 'error'
							})
						}
					}
				});
			},
			goDetail(item) {
				uni.navigateTo({
					url: "/subPage_receiptOrder/receiptDetail?id=" + item.id
				})
			}
		},
		components: {

		}
	}
</script>

<style lang="scss" scoped>
	.index {
		height: 100%;
		overflow: hidden;

		.search-wrapper {
			background-color: #ffffff;
			margin: 3upx 0;
			padding: 10upx 20upx;
			position: relative;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.date-wrapper {
				display: flex;
				align-items: center;
			}

			.input {
				border-radius: 10upx;
				border: 2upx solid #acacac;
				height: 70upx;
				width: 100%;
				padding: 0 120upx 0 30upx;
				box-sizing: border-box;
				font-size: 32upx;
			}

			.icon {
				position: absolute;
				top: 50%;
				transform: translateY(-50%);
				right: 280upx;
				width: 26upx;
				height: 26upx;
			}

			.close {
				position: absolute;
				top: 50%;
				transform: translateY(-50%);
				right: 330upx;
			}

			.search-btn {
				width: 150upx;
				background-color: #555BFF;
				color: #ffffff;
				height: 70upx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 10upx;
				margin-left: 10upx;
				font-size: 28upx;

				&.scan {
					width: 250upx;
				}
			}
		}

		.item {
			margin: 20upx;
			border-radius: 20upx;
			background-color: #ffffff;
			overflow: hidden;

			.supplier-wrapper {
				padding: 20upx 30upx;
				background-color: #F5F6FA;

				.supplier-info {
					display: flex;
					align-items: center;
					margin-bottom: 10upx;
				}

				.supplier-address {
					font-size: 30upx;
					color: #666666;
				}

				.name {
					flex: 1;
					font-size: 34upx;
					//width: 500rpx;
					text-overflow: -o-ellipsis-lastline;
					overflow: hidden; //溢出内容隐藏
					text-overflow: ellipsis; //文本溢出部分用省略号表示
					display: -webkit-box; //特别显示模式
					-webkit-line-clamp: 1; //行数
					line-clamp: 1;
					-webkit-box-orient: vertical; //盒子中内容竖直排列
					font-weight: bold;
					color: #343434;
				}

				.tel {
					font-size: 32upx;
					color: #343434;
				}
			}

			.product-info {
				overflow: hidden;
				padding: 0 30upx;

				.productName-wrapper {
					margin-top: 20upx;
					display: flex;
					align-items: center;

					.productName {
						flex: 1;
						font-size: 32upx;
						line-height: 38upx;
						//width: 500rpx;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden; //溢出内容隐藏
						text-overflow: ellipsis; //文本溢出部分用省略号表示
						display: -webkit-box; //特别显示模式
						-webkit-line-clamp: 2; //行数
						line-clamp: 2;
						-webkit-box-orient: vertical; //盒子中内容竖直排列
						font-weight: bold;
						color: #464646;
					}
				}

				.info-wrapper {
					display: flex;
					align-items: center;
					margin-top: 15upx;
					font-size: 32upx;
					color: #434343;

					.label {
						width: 130upx;
					}
				}
			}

			.testing-wrapper {
				margin: 20upx;
				border-top: 1upx dashed #cecece;
				padding: 0 10upx 10upx 10upx;

				.testing-title {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 20upx;
					color: #434343;
					font-size: 32upx;
				}

				.images-wrapper {
					display: flex;
					align-items: center;
					flex-wrap: wrap;
					margin-top: 20upx;

					.reject-image {
						position: relative;
						width: 31%;
						height: 206upx;
						border-radius: 20upx;
						overflow: hidden;
						margin-left: 2%;
						margin-bottom: 20upx;
					}
				}
			}
		}
	}
</style>